package com.geek.javase.ch13.work;

/*
 *@author wangpeng
 *2025/10/24 19:42
 *@description
 * 读取emp.txt文件，其信息为  张三#123 ，完成用户登录
*/

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Demo2 {
    public static void main(String[] args) {
        boolean flag = false;
        try(
                BufferedReader br = new BufferedReader(new FileReader("emp.txt"));
            ) {
            String line;
            while ((line = br.readLine()) != null) {
                //按照"#"分割用户名和密码
                String[] userInfo = line.split("#");
                if(userInfo.length == 2) {
                    String storeUserName = userInfo[0];
                    String storePassword = userInfo[1];
                    if(storeUserName.equals("张三") && storePassword.equals("111")) {
                        //登录成功
                        flag = true;
                    }
                }
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        if(flag){
            System.out.println("登录成功！");
        }else{
            System.out.println("登录失败！");
        }
    }
}
